package com.snail.controller.aichat;

/**
 * @author ysc
 * @descrpiton ai生成问题的返回格式，，使用openai兼容的标准
 * @param
 * @date 2025/7/15 11:52
 **/
public class ChatResponse {
    private String id;
    private String object;
    private ChatChoice[] choices;

    public static class ChatChoice {
        private int index;
        private Message message;

        public static class Message {
            private String role;
            private String content;
            // Getters and Setters

            public String getRole() {
                return role;
            }

            public void setRole(String role) {
                this.role = role;
            }

            public String getContent() {
                return content;
            }

            public void setContent(String content) {
                this.content = content;
            }
        }

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        public Message getMessage() {
            return message;
        }

        public void setMessage(Message message) {
            this.message = message;
        }
    }

    // Getters and Setters

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getObject() {
        return object;
    }

    public void setObject(String object) {
        this.object = object;
    }

    public ChatChoice[] getChoices() {
        return choices;
    }

    public void setChoices(ChatChoice[] choices) {
        this.choices = choices;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("ChatResponse{");
        sb.append("id='").append(id).append('\'');
        sb.append(", object='").append(object).append('\'');
        sb.append(", choices=[");

        if (choices != null) {
            for (int i = 0; i < choices.length; i++) {
                if (i > 0) {
                    sb.append(", ");
                }
                ChatChoice choice = choices[i];
                sb.append("{index=").append(choice.getIndex());
                if (choice.getMessage() != null) {
                    sb.append(", message={role='").append(choice.getMessage().getRole())
                            .append("', content='").append(choice.getMessage().getContent()).append("'}");
                } else {
                    sb.append(", message=null");
                }
                sb.append("}");
            }
        }

        sb.append("]}");
        return sb.toString();
    }
}
